﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NLBS.Data;
using NLBS.Security;
using NLBS.Framework;


namespace NLBS
{
    public partial class Login : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["act"] != null)
            {
                if (Request.QueryString["act"] == "logout")
                {
                    FormsAuthentication.SignOut();
                    BlogInfo.Instance().CurrentUser = null;
                    Response.Redirect("/default.aspx");
                }
            }
            
            if (Request.IsAuthenticated)
            {
                Response.Redirect("/default.aspx");
            }
            
            
            agree.ServerClick += new EventHandler(agree_ServerClick);
            this.Title = "登录";
        }

       

        void agree_ServerClick(object sender, EventArgs e)
        {
           bool result = DbProvider.Instance().ValidateUser(username.Value, StringSecurity.StringToSHA1Hash(password.Value));
           if (result)
           {
               FormsAuthentication.SetAuthCookie(username.Value, true);

               Response.Redirect("/default.aspx");
           }
           else
           {
               Label1.Text = "登陆失败";
           }
        }
    }
}
